const userAvatar = document.getElementById('userAvatar');
const dropdownMenu = document.getElementById('dropdownMenu');

// 点击头像切换菜单显示
userAvatar.addEventListener('click', function (e) {
    e.stopPropagation();
    dropdownMenu.classList.toggle('show');
});

// 点击菜单外区域关闭菜单
document.addEventListener('click', function (e) {
    if (!userAvatar.contains(e.target) && !dropdownMenu.contains(e.target)) {
        dropdownMenu.classList.remove('show');
    }
});

// 防止点击菜单时关闭
dropdownMenu.addEventListener('click', function (e) {
    e.stopPropagation();
});

// 为菜单项添加点击效果
const menuItems = document.querySelectorAll('.menu-item');
menuItems.forEach(item => {
    item.addEventListener('click', function (e) {
        e.preventDefault();

        // 添加点击反馈
        this.style.backgroundColor = this.classList.contains('logout') ? '#ffeaea' : '#f0f7ff';

    });
});
